import * as Cesium from "cesium/Cesium";
import Layer from '../../src/layer/Layer.js';
import { LayerEventType } from '../../src/event/EventType.js';
import RadarScanner from '../../src/overlay/animation/RadarScanner.js';
import { OverlayEventType } from "../../src/event/EventType.js";

export default function add_overlay_radar(earth){
    let layer = new Layer("radar");
    layer.on(LayerEventType.ADD, evt=>{
        console.log(evt.obj.name);
    })

    earth.addLayer(layer);

    //99.791779°, 纬度:28.940104°, 高度:8308.819663米

    // let pos = {
    //     lng : 121.489206,
    //     lat : 31.241320,
    //     alt : 0
    // };
    let pos = {
        lng : 99.791779,
        lat : 28.940104,
        alt : 0
    };
    let radius = 10000;
    
    let red = create_radar_red(pos, radius);
    layer.addOverlay(red);
    red.start();

    // pos.lng = pos.lng + 0.5;
    // pos.lat = pos.lat + 0.5;
    // let green = create_radar_green(pos, radius);    
    // layer.addOverlay(green);    
    // //green.start();
    // window.green = green;
    
    pos.alt = 100000;
    earth.zoomToPosition(pos);
    
    //删除overlay
    //layer.removeOverlay(tileset);
}

function create_radar_red(pos, radius){

    let options= {
        color : Cesium.Color.RED,
        speed : 3
    }

    let radar = new RadarScanner(pos, radius, options);
    radar.on(OverlayEventType.ADD, evt=>{
        console.log(evt.obj.id);
    });

    return radar;
}

function create_radar_green(pos, radius){

    let options= {
        color : Cesium.Color.GREEN,
        speed : 3
    }

    let radar = new RadarScanner(pos, radius, options);
    radar.on(OverlayEventType.ADD, evt=>{
        console.log(evt.obj.id);
    });

    return radar;
}